package com.amoyt.project.controller.admin;

import com.amoyt.project.domain.dto.query.FeedbackPageQuery;
import com.amoyt.project.domain.dto.update.HandleFeedBackUpdateDto;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.exception.BusinessException;
import com.amoyt.project.exception.enums.BusinessExceptionEnum;
import com.amoyt.project.service.admin.FeedBackHandleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Date: 2025/8/28
 * @Time: 15:38
 * @Author: TQ_QT
 * @Description:
 */
@RestController
@RequestMapping("/admin/feedback")
@Tag(name = "反馈处理接口",description = "反馈处理接口")
public class FeedBackHandleController {

    @Autowired
    private FeedBackHandleService feedBackHandleService;

    /**
     * 用户反馈列表
     * @param query
     * @return
     */
    @Operation(summary = "用户反馈列表",method = "POST")
    @PostMapping("/list")
    @Parameter(name = "token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @PreAuthorize("hasAnyRole('super_admin','prov_admin','city_admin','region_admin')")
    public Result list(@RequestBody FeedbackPageQuery query){
        if (query == null || query.getPage() == null || query.getPageSize() == null){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }
        return feedBackHandleService.list(query);
    }

    /**
     * 处理意见反馈
     * @param handleFeedBackDto
     * @return
     */
    @PutMapping("/handle")
    @Operation(summary = "处理意见反馈",method = "PUT")
    @Parameter(name = "token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @PreAuthorize("hasAnyRole('super_admin','prov_admin','city_admin','region_admin')")
    public Result handleFeedBack(@RequestBody HandleFeedBackUpdateDto handleFeedBackDto) {
        if (handleFeedBackDto == null || handleFeedBackDto.getBackId() == null){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }

        return feedBackHandleService.handleFeedBack(handleFeedBackDto);
    }
}
